package com.yule.utils;

import com.alibaba.fastjson.JSON;
import com.yule.config.DynamicDataSourceContext;
import com.yule.system.model.SystemUser;
import org.apache.shiro.SecurityUtils;

public class UserUtils {

    public UserUtils(){}

    public static SystemUser getUser(Object object) {
        SystemUser userInfo = new SystemUser();
        if (object instanceof SystemUser) {
            userInfo = (SystemUser) object;
        } else {
            userInfo = JSON.parseObject(JSON.toJSON(object).toString(), SystemUser.class);
        }
        //return (UserInfo) object;
        return userInfo;
    }
    
    public static SystemUser setDBType() {
        Object obj = SecurityUtils.getSubject().getPrincipal();
    	SystemUser user = getUser(obj);
        DynamicDataSourceContext.setDBType(user.getCorpLoginName());
        return user;
    }
    
    public static void setDefaultDBType() {
    	DynamicDataSourceContext.setDBType("default");
    }

}
